package Objetos;

import java.awt.Graphics;
import java.awt.*;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;


public class TextoImprimible implements Printable {

    String texto = null;

    public TextoImprimible(String texto) {
        this.texto = texto;
    }

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        try {
            if (pageIndex == 0) {
            	String n[]=texto.split("\n"); 
            		int f=0;
            	for(int i=0;i<n.length;i++){
            		graphics.setFont(new Font(Font.MONOSPACED,Font.PLAIN,11));
            		graphics.drawString(n[i], 100, 100+f);
            		f+=15;
            	}
                return PAGE_EXISTS;
            } else {
                return NO_SUCH_PAGE;
            }
        } catch (Exception e) {
             throw new PrinterException(e.getMessage());
        }
    }
}
